local xunji = fk.CreateSkill{
    name = "jinld__xunji",
}

Fk:loadTranslationTable{
    ["jinld__xunji"] = "勋济",
    [":jinld__xunji"] = "结束阶段，若你本回合使用过的伤害类牌均造成过伤害，你可以视为对一名其他角色使用一张【杀】（疑兵→目标+1）。",

    ["#jinld__xunji-choose"] = "勋济：选择一名其他角色，视为对其使用一张【杀】（疑兵→目标+1）",

    ["$jinld__xunji1"] = "天统之境，岂容丑虏犯边！",
    ["$jinld__xunji2"] = "凉州有危，臣者当济。",
}

xunji:addEffect(fk.EventPhaseStart,{
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(xunji.name) and player.phase == Player.Finish then
            local room = player.room
            local cards = {}
            room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                local use = e.data
                if use.from == player and use.card.is_damage_card then
                    table.insertIfNeed(cards, use.card)
                end
            end, Player.HistoryTurn)
            if #cards == 0 then return end
            room.logic:getActualDamageEvents(1, function(e)
                local damage = e.data
                if table.contains(cards, damage.card) then
                    table.removeOne(cards, damage.card)
                end
            end, Player.HistoryTurn)
            if #cards == 0 then return true end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player), function(p)
            return player:canUseTo(Fk:cloneCard("slash"), p, { bypass_distances = false, bypass_times = true })
        end)
        local to = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            skill_name = xunji.name,
            prompt = "#jinld__xunji-choose",
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self, { tos = to })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        if to.dead then return end
        local use = room:useVirtualCard("slash", nil, player, to, xunji.name, true)
        if use then
            use.card.extra_data = use.card.extra_data or {}
            use.card.extra_data.heg_variation = { "@heg_yibing-public", "variation_addtarget" }
        end
    end,
})

return xunji